package com.young.core.manager.impl;


import com.young.common.query.Pagination;
import com.young.common.query.Query;
import com.young.core.dao.JobDao;
import com.young.core.dao.ProjectDao;
import com.young.core.domain.ProjectDO;
import com.young.core.manager.ProjectManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * name: ProjectManagerImpl
 *
 * @author zhaoxinbo
 * @Description
 * @Date create in 2020/9/21 14:30.
 */
@Component
public class ProjectManagerImpl implements ProjectManager {

    @Autowired
    private ProjectDao projectDao;

//    @Autowired
//    private ProjectUserDao projectUserDao;

    @Autowired
    private JobDao jobDao;

    @Override
    public void insert(ProjectDO project) {
        this.projectDao.insert(project);

//        ProjectUserDO user = new ProjectUserDO();
//        user.setProject(project.getName());
//        user.setAccountName(project.getOperator());
//        this.projectUserDao.insert(user);
    }

    @Override
    public void update(ProjectDO project) {
        this.projectDao.update(project);
    }

    @Override
    public void audit(int id, boolean auditable) {
        this.projectDao.audit(id, auditable);
    }

    @Override
    public ProjectDO get(int id, boolean include) {
        ProjectDO project =  this.projectDao.get(id);
//        if(include && project != null) {
//            List<ProjectUserDO> users = this.projectUserDao.getAll(project.getName());
//            project.setUsers(users);
//        }
        return project;
    }

    @Override
    public ProjectDO get(String name, boolean include) {
        ProjectDO project = this.projectDao.get(name);
//        if(include && project != null) {
//            List<ProjectUserDO> users = this.projectUserDao.getAll(project.getName());
//            project.setUsers(users);
//        }
        return project;
    }

    @Override
    public Pagination<ProjectDO> query(Query query) {
        return this.projectDao.query(query);
    }

    @Override
    public List<ProjectDO> search(String pattern) {
        return this.projectDao.search(pattern);
    }

    @Override
    public int delete(String name) {
//        projectUserDao.delete(name);
        return this.projectDao.delete(name);
    }
}
